// 最基础的hooks
import React, { useState, useEffect } from 'react';
let init = 1;

const UseState = () => {
    const [num, setNum] = useState(0);
    useEffect(() => {
        // 三个生命周期函数
        console.log('老弟你来了');
        return () => {
            console.log('leave');
        }

    }, [num]);
    // useEffect(() => {}, []) 第二参数空数组的意思是只有被销毁才执行leave
    // useEffect(() => {}, [num]) 当某值变化的时候
    return(
        <div className='stateBox'>
            <div>
                {num}
            </div>
            <button onClick={() => {setNum(num + 1)}}>
                +1
            </button>
        </div>
    )
};

export default React.memo(UseState);